import { PicClassifyEntity } from 'src/entities/picClassify.entity';
import { BaseEntity } from './base.entity';
import { Column, Entity, ManyToMany, OneToMany } from 'typeorm';
import SpecEntity from './spec.entity';

@Entity()
export class PicEntity extends BaseEntity {
  @Column({ type: 'varchar' })
  pic_name: string;
  @Column({ type: 'varchar' })
  img_url: string; // 压缩大图
  @Column({ type: 'varchar' })
  high_img_url: string; // 高清大图
  @Column({ type: 'varchar' })
  author: string;
  @Column({ type: 'int' })
  max_height: number;
  @Column({ type: 'int' })
  max_width: number;
  @Column({ type: 'varchar' })
  privide_resolution: string;
  @ManyToMany(
    type => PicClassifyEntity,
    picClassifyEntity => picClassifyEntity.pics,
    {
      onDelete: 'CASCADE',
    },
  )
  classify: PicClassifyEntity[];
  @Column({ type: 'longtext' })
  img_info: string;
  @Column({ type: 'int', nullable: true, default: 0 })
  views: number;
  @Column({ type: 'varchar', nullable: true })
  thumb: string; // 缩略图
  @Column({ type: 'varchar', nullable: true })
  list_img_url: string; // 瀑布流需要500*500
  @OneToMany(
    type => SpecEntity,
    specEntity => specEntity.pic,
    { cascade: true },
  )
  specs: SpecEntity[];
}
